#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/6/16 0016 22:22
# @Author  : wzy
# @Site    : 
# @File    : operate_config.py
# @Software: PyCharm

from deepdiff import DeepDiff
from Util.operate_json import operateJson

# print(get_value('api3/getbanneradvertver2',"/Config/code_message.json"))
'''[
        {"1006,":"token error"},
        {"10001":"用户名错误"},
        {"10002":"密码错误"}
    ]'''

def operate_result(url, code):
    '''
    :param url:
    :param code:
    :return:获取
    '''
    data = operateJson.get_json_value(url, "code_message.json")
    if data != None:
        for i in data:
            message = i.get(str(code))
            if message:
                return message
    return None


def get_result_json(url, status):
    '''
    :param url:
    :param status:
    :return: 获取result.json值
    '''
    data = operateJson.get_json_value(url, "result.json")
    if data != None:
        for i in data:
            message = i.get(status)
            if message:
                return message
    return None

def cmp_result_json(dict1, dict2):
    '''
    校验结果与返回内容是否完全一致
    '''
    if isinstance(dict1, dict) and isinstance(dict2, dict):
        cmp_dict = DeepDiff(dict1, dict2, ignore_order=True).to_dict()
        if cmp_dict.get("dictionary_item_added"):
            return False
        else:
            return True
    return False


if __name__ == "__main__":
    # dict2 = {"aaa": "ddd", "aaa1": "A1A", "bbb": "BBBB", "CC": [{"11": "22"}, {"11": "44"}]}
    # dict1 = {"aaa": "AAA", "bbb": "BBBB", "aaa3": "A1A", "CC": [{"11": "22"}, {"11": "44"}]}
    #print(get_result_json('api3/beta4','error'))
    excepect_result = get_result_json('api3/beta4','error')
    result = operate_result(res, excepect_result)
    print()
    #print(operate_result('api3/getbanneradvertver2','1006'))
    #print(cmp_result_json(dict1,dict2))




